package com.dslcode.cloud.common.api.goods;

import com.dslcode.cloud.common.dto.goods.GoodsBuyDTO;
import com.dslcode.cloud.common.dto.goods.GoodsCommonDetailDTO;
import com.dslcode.cloud.common.model.goods.GoodsCommon;
import com.dslcode.cloud.common.utils.AjaxResponse;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * Created by dongsilin on 2017/10/10.
 */
public interface GoodsAPI {

    /**
     * url请求前缀
     */
    String REQUEST_PREFIX = "goods";

    /**
     * 检查库存
     * @param id
     * @param buyNum
     * @return
     * @throws Exception
     */
    @GetMapping(REQUEST_PREFIX + "/checkStorage/{id}")
    AjaxResponse<GoodsBuyDTO> checkStorage(@PathVariable(name = "id") Long id, @RequestParam(name = "buyNum", defaultValue = "1") int buyNum) throws Exception ;

    /**
     * 扣减库存
     * @param goodsBuyDTOs
     * @return
     * @throws Exception
     */
    @PutMapping(REQUEST_PREFIX + "/reduceStorage")
    AjaxResponse reduceStorage(@RequestBody Set<GoodsBuyDTO> goodsBuyDTOs);

    @GetMapping(REQUEST_PREFIX)
    AjaxResponse<PageInfo<GoodsCommon>> list(@RequestParam(name = "pageNum", defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", defaultValue = "10") int pageSize);

    @GetMapping(REQUEST_PREFIX + "/{id}")
    AjaxResponse<GoodsCommon> one(@PathVariable(name = "id") Long id);

    @GetMapping(REQUEST_PREFIX + "/detail/{id}")
    AjaxResponse<GoodsCommonDetailDTO> detail(@PathVariable(name = "id") Long id);

}
